<?php
//isset()检测变量是否设置
  if(isset($_REQUEST['authcode'])){
    session_start();
    //strtolower()小写函数
    if(strtolower($_REQUEST['authcode'])== $_SESSION['code']){
      //跳转页面
      echo "<script language=\"javascript\">";
      echo "document.location=\"./index.php\"";
      echo "</script>";
    }else{
      //提示以及跳转页面
      echo "<script language=\"javascript\">";
      echo "alert('输入错误!');";
      echo "document.location=\"/adduser.php\"";
      echo "</script>";
    }
    exit();
include('config/config.php');
$conn = mysqli_connect(HOST, USER, PASS, DBNAME) or die("数据库服务器连接错误" . mysqli_connect_error());      //连接数据库
mysqli_query($conn,"set names utf8");    //设置编码格式
$name = $_POST['uname'];           //获取用户名
$pass = $_POST['upass'];       //获取密码  
$sql="insert into root(username,password) values('$name','$pass')";
echo $sql;
//应用mysqli_query()函数执行insert…into语句添加数据到数据库，并使用if语句判断是否添加成功
$result = mysqli_query($conn,$sql);
if ($result) {
 echo "<script>alert('用户添加成功!'); window.location.href = 'login.php';</script>";
} else {
    echo "<script>alert('用户添加失败!'); window.location.href = 'register.php';</script>";
}


mysqli_close($conn);           
?>